#include "../include/SavingsAccount.hh"
#include "../include/CheckingAccount.hh"
#include <iostream>
#include <iomanip>

SavingsAccount::SavingsAccount(std::string id, std::string owner, double initialBalance)
    : Account(id, owner, initialBalance) {
}

void SavingsAccount::displayDetails() const {
    std::cout << "===== 储蓄账户 =====" << std::endl;
    std::cout << "账号: " << getAccountId() << std::endl;
    std::cout << "持有人: " << getOwnerName() << std::endl;
    
    // 显示各种货币的余额
    std::cout << "人民币余额: ¥" << std::fixed << std::setprecision(2) << getBalance(Currency::CNY) << std::endl;
    std::cout << "美元余额: $" << std::fixed << std::setprecision(2) << getBalance(Currency::USD) << std::endl;
    std::cout << "欧元余额: €" << std::fixed << std::setprecision(2) << getBalance(Currency::EUR) << std::endl;
}

std::string SavingsAccount::getAccountTypeName() const {
    return "储蓄账户";
}

bool SavingsAccount::canDeposit() const {
    // 储蓄账户不能直接存款
    return false;
}

bool SavingsAccount::canWithdraw() const {
    // 储蓄账户不能直接取款
    return false;
}

bool SavingsAccount::canTransferTo(const Account& destinationAccount) const {
    // 储蓄账户只能转账到同一客户的支票账户
    // 检查目标账户是否是支票账户，以及是否属于同一客户
    
    // 尝试将目标账户转换为支票账户
    const CheckingAccount* checkingAccount = dynamic_cast<const CheckingAccount*>(&destinationAccount);
    
    // 如果不是支票账户，则不能转账
    if (!checkingAccount) {
        return false;
    }
    
    // 检查是否属于同一客户（通过比较持有人名称）
    return (checkingAccount->getOwnerName() == this->getOwnerName());
}

bool SavingsAccount::deposit(double amount, const std::string& note) {
    // 储蓄账户不能直接存款，重写以实现限制
    std::cout << "错误：储蓄账户不能直接存款。请通过支票账户转账。" << std::endl;
    return false;
}

bool SavingsAccount::withdraw(double amount, const std::string& note) {
    // 储蓄账户不能直接取款，重写以实现限制
    std::cout << "错误：储蓄账户不能直接取款。请先转账到支票账户。" << std::endl;
    return false;
} 